package com.zxl.practice.aop;

import com.zxl.practice.aop.core.*;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class AopApplication {

	public static void main(String[] args) {
		SpringApplication.run(AopApplication.class, args);

		// 子类继承的动态代理
		People people = (People) new ProxyFactoryByCglib(new People()).getProxyIntance();
		people.eat();
		if(people instanceof People){ // cglib采用的字节码增强，生成的对象就是目标对象的子类，所以为true
			people.sleep();
		}

		// jdk动态代理生成代理对象
		Animal animal=(Animal) new ProxyFactoryByJdk(new Wolf()).getProxyInstance();
		animal.eat();
		if(animal instanceof Wolf ){ //因为是采用的jdk的动态代理，所以 animal对象的类型 不是 wolf, 表达式为 false
			((Wolf) animal).sleep();
		}
	}

}
